package com.woniuxy.repay.aspect;

import cn.hutool.extra.mail.MailUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author shichen
 * @create 2021-11-24-16:39
 * @description
 */
@Aspect
@Component
@Slf4j
public class ExceptionAspect {

    @AfterThrowing(value = "execution(* com.woniuxy.repay..*.*(..))",throwing = "ex")
    void exceptionHandler(Throwable ex){
        log.debug("异常通知 : {}",ex);
        String msg = "你写的程序出bug了 : " + ex.toString() + new Date().toString();
        MailUtil.send("1282399009@qq.com", "bug 来了!", msg, false);
    }
}
